//
//  CutPriceCell.m
//  LoveCar
//
//  Created by dlios on 15/5/29.
//  Copyright (c) 2015年 薛森鸿. All rights reserved.
//

#import "CutPriceCell.h"
#import "UIWindow+YUBottomPoper.h"
#import <Masonry/Masonry.h>

@implementation CALayer (Additions)
- (void)setBorderColorFromUIColor:(UIColor *)color
{
    self.borderColor = color.CGColor;
}
@end

@implementation CutPriceCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}
- (void)createView {
    self.backgroundColor = [UIColor whiteColor];
    
    self.name = [[UILabel alloc] init];
    [self.contentView addSubview:_name];
    [_name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).with.offset(10);
        make.top.equalTo(self.contentView).with.offset(10);
        make.width.with.mas_equalTo(@240);
        make.height.with.mas_equalTo(@30);
    }];
    [_name release];
    
    self.price = [[UILabel alloc] init];
    [self.contentView addSubview:_price];
    _mprice.textAlignment = 2;
    [_price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).with.offset(-10);
        make.top.equalTo(self.contentView).with.offset(10);
        make.width.with.mas_equalTo(@60);
        make.height.with.mas_equalTo(@30);
    }];
    _price.textColor = [UIColor redColor];
    [_price release];
    
    UILabel *s = [[UILabel alloc] init];
    [self.contentView addSubview:s];
    s.textAlignment = 1;
    [s mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).with.offset(10);
        make.top.equalTo(self.contentView).with.offset(40);
        make.width.with.mas_equalTo(@30);
        make.height.with.mas_equalTo(@30);
    }];
    s.text = @"[4s]";
    s.textColor = [UIColor redColor];
    s.font = [UIFont systemFontOfSize:13];
    [s release];
    
    self.dealer = [[UILabel alloc] init];
    [self.contentView addSubview:_dealer];
    _dealer.textAlignment = 1;
    [_dealer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(s.mas_right).with.offset(0);
        make.top.equalTo(self.contentView).with.offset(40);
        make.width.with.mas_equalTo(@110);
        make.height.with.mas_equalTo(@30);
    }];
    _dealer.textColor = [UIColor lightGrayColor];
    _dealer.font = [UIFont systemFontOfSize:13];
    [_dealer release];
    
    UILabel *ss = [[UILabel alloc] init];
    [self.contentView addSubview:ss];
    ss.textAlignment = 1;
    [ss mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dealer.mas_right).with.offset(2);
        make.top.equalTo(self.contentView).with.offset(45);
        make.width.with.mas_equalTo(@55);
        make.height.with.mas_equalTo(@20);
    }];
    ss.text = @"现车充足";
    ss.textColor = [UIColor lightGrayColor];
    ss.font = [UIFont systemFontOfSize:13];
    ss.layer.borderWidth = 1;
    ss.layer.borderColor = [UIColor lightGrayColor].CGColor;
    [ss release];
    
    self.mprice = [[UILabel alloc] init];
    [self.contentView addSubview:_mprice];
    _mprice.textAlignment = 2;
    [_mprice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).with.offset(-10);
        make.top.equalTo(self.contentView).with.offset(40);
        make.width.with.mas_equalTo(@50);
        make.height.with.mas_equalTo(@30);
    }];
    _mprice.textColor = [UIColor lightGrayColor];
    _mprice.font = [UIFont systemFontOfSize:13];
    [_mprice release];
    
    UILabel *line = [[UILabel alloc] init];
    [self.contentView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.mprice);
        make.width.with.mas_equalTo(@50);
        make.height.with.mas_equalTo(@1);
    }];
    line.backgroundColor = [UIColor lightGrayColor];
    [line release];
    
    self.cutprice = [[UILabel alloc] init];
    [self.contentView addSubview:_cutprice];
    _cutprice.textAlignment = 2;
    [_cutprice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).with.offset(-10);
        make.top.equalTo(self.contentView).with.offset(65);
        make.width.with.mas_equalTo(@40);
        make.height.with.mas_equalTo(@30);
    }];
    _cutprice.textColor = [UIColor colorWithRed:38.0 / 256 green:150.0 / 256 blue:38.0 / 256 alpha:1];
    _cutprice.font = [UIFont systemFontOfSize:13];
    [_cutprice release];
    
    UIImageView *down = [[UIImageView alloc] init];
    [self.contentView addSubview:down];
    [down mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.cutprice.mas_left).with.offset(0);
        make.top.equalTo(self.contentView).with.offset(73);
        make.width.with.mas_equalTo(@15);
        make.height.with.mas_equalTo(@15);
    }];
    [down setImage:[UIImage imageNamed:@"down.png"]];
    [down release];
    
    self.tel = [[UIButton alloc] init];
    UIButton *b = [[UIButton alloc] init];
    [self.contentView addSubview:_tel];
    [self.contentView addSubview:b];
    [_tel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).with.offset(10);
        make.right.equalTo(b.mas_left).with.offset(-10);
        make.top.equalTo(self.contentView).with.offset(95);
        make.width.with.mas_equalTo(b.mas_width);
        make.height.with.mas_equalTo(@30);
    }];
    [b mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_tel.mas_right).with.offset(10);
        make.right.equalTo(self.contentView).with.offset(-10);
        make.top.equalTo(self.contentView).with.offset(95);
        make.width.with.mas_equalTo(_tel.mas_width);
        make.height.with.mas_equalTo(@30);
    }];
    _tel.layer.borderWidth = 1;
    _tel.layer.borderColor = [UIColor lightGrayColor].CGColor;
    b.layer.borderWidth = 1;
    b.layer.borderColor = [UIColor orangeColor].CGColor;
    [_tel setTitle:@"dd" forState:UIControlStateNormal];
    [b setTitle:@"电话咨询" forState:UIControlStateNormal];
    [_tel setTitleColor:[UIColor colorWithRed:38.0 / 256 green:150.0 / 256 blue:38.0 / 256 alpha:1] forState:UIControlStateNormal];
    [b setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    _tel.titleLabel.font = [UIFont systemFontOfSize:15];
    b.titleLabel.font = [UIFont systemFontOfSize:15];
    [_tel addTarget:self action:@selector(telAction:) forControlEvents:UIControlEventTouchUpInside];
    [b addTarget:self action:@selector(hi:) forControlEvents:UIControlEventTouchUpInside];
    [b release];
    
    UIImageView *phone = [[UIImageView alloc] init];
    [self.contentView addSubview:phone];
    [phone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.tel).with.offset(5);
        make.centerY.equalTo(self.tel);
        make.width.with.mas_equalTo(@15);
        make.height.with.mas_equalTo(@15);
    }];
    [phone setImage:[UIImage imageNamed:@"tel.png"]];
    [phone release];
}
- (void)telAction:(id)sender {
    [self.window  showPopWithButtonTitles:@[self.phoneNum, @"拨打电话?"] styles:@[YUSuccessStyle, YUDangerStyle] whenButtonTouchUpInSideCallBack:^(int index  ) {
        if (index == 0) {
            NSLog(@"%@", _tel.currentTitle);
        }
        if (index == 1) {
            NSMutableString * str = [[NSMutableString alloc] initWithFormat:@"tel:%@",_tel.currentTitle];
            UIWebView * callWebview = [[UIWebView alloc] init];
            [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
            [self.contentView addSubview:callWebview];
            [callWebview release];
            [str release];
        }
        if (index == 2) {
            [self.window disMissPopSelectView];
        }
    }];
}
- (void)hi:(id)sender {
    [self.window  showPopWithButtonTitles:@[self.phoneNum, @"询问价格?"] styles:@[YUSuccessStyle, YUDangerStyle] whenButtonTouchUpInSideCallBack:^(int index  ) {
        if (index == 0) {
            NSLog(@"%@", _tel.currentTitle);
        }
        if (index == 1) {
            NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",_tel.currentTitle];
            UIWebView * callWebview = [[UIWebView alloc] init];
            [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
            [self.contentView addSubview:callWebview];
            [callWebview release];
            [str release];
        }
        if (index == 2) {
            [self.window disMissPopSelectView];
        }
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
}
- (void)dealloc {
    [_name release];
    [_price release];
    [_dealer release];
    [_mprice release];
    [_cutprice release];
    [_tel release];
    [_phoneNum release];
    [super dealloc];
}


@end
